home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 48 / Amiga Format CD48 (1999-12-13)(Future Publishing)(GB)(Track 1 of 2)[!][issue 2000-01].iso / -serious- / programming / c / supralib / developer / source / makepath.c < prev    next >
C/C++ Source or Header  |  1999-11-01  |  2KB  |  79 lines

  1. /****** MakePath *********************************************************
  2. *
  3. *   NAME
  4. *       MakePath -- Creates all new directories in a path (V10)
  5. *
  6. *   SYNOPSIS
  7. *       suc = MakePath(path)
  8. *
  9. *       BOOL = MakePath(char *);
  10. *
  11. *   FUNCTION
  12. *       This function creates a whole specified path of directories.
  13. *       It works similar to CreateDir() except that it can create
  14. *       more subdirs at once. User does not have to care if all
  15. *       sub dirs in a specified path already exist or not.
  16. *
  17. *   INPUTS
  18. *       path - pointer to a path string to create. A path can be
  19. *       relative to a current dir or absolute.
  20. *
  21. *   RESULT
  22. *       suc - TRUE if succeeds (path was created). FALSE if a path
  23. *       could not be created.
  24. *
  25. *   EXAMPLE
  26. *
  27. *       suc = MakePath("RAM:way/to/many/dirs");
  28. *
  29. *       The above function will try to make all non-existing dirs
  30. *       in a path RAM:way/to/many/dirs.
  31. *
  32. *   SEE ALSO
  33. *       CreateDir()
  34. *
  35. *********************************************************************/
  36.  
  37. #include<proto/dos.h>
  38. #include<dos/dos.h>
  39. #include<string.h>
  40.   
  41. BOOL MakePath(char *path)
  42. {
  43.     char *p=path;
  44.     BPTR lock;
  45.     struct FileInfoBlock fib;
  46.     BOOL err=FALSE;
  47.  
  48.     do
  49.     {
  50.         p = strchr(p,'/');
  51.         if (p != NULL) p[0] = '\0';
  52.         lock = Lock(path, ACCESS_READ);
  53.         if (lock)
  54.         {
  55.             if (Examine(lock, &fib))
  56.             {
  57.                 if (fib.fib_DirEntryType < 0) err = TRUE;
  58.             }
  59.             else err = TRUE;
  60.             UnLock(lock);
  61.             if (err) return(FALSE);
  62.         }
  63.         else
  64.         {
  65.             lock = CreateDir(path);
  66.             if (lock) UnLock(lock);
  67.             else return(FALSE);
  68.         }
  69.         if (p != NULL)
  70.         {
  71.             p[0] = '/';
  72.             p++;
  73.         }
  74.     }
  75.     while(p != NULL);
  76.     return(TRUE);
  77. }
  78.  
  79.